package com.kvest.sqlitetest.datastorage.sqlitestorage;

import android.content.Context;
import android.database.Cursor;

/**
 * Created with IntelliJ IDEA.
 * User: Kvest
 * Date: 16.07.13
 * Time: 21:19
 * To change this template use File | Settings | File Templates.
 */
public class MultithreadingSQLiteManager {
    private static MultithreadingSQLiteManager instance;
    private static final Object lock = new Object();

    public static MultithreadingSQLiteManager getInstance() {
        synchronized (lock) {
            if (instance == null) {
                instance = new MultithreadingSQLiteManager();
            }
        }

        return instance;
    }

    private MultithreadingTestHelper multithreadingTestHelper;

    private MultithreadingSQLiteManager() {
        multithreadingTestHelper = null;
    }

    public void init(Context context) {
        multithreadingTestHelper = new MultithreadingTestHelper(context);
    }

    public void close() {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.close();
        }
    }

    public void clear() {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.clear();
        }
    }

    public void printAll() {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.printAll();
        }
    }

    public void fill() {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.fill();
        }
    }

    public Cursor getTableCursor(String tableName) {
        if (multithreadingTestHelper != null) {
            return multithreadingTestHelper.getTableCursor(tableName);
        }

        return null;
    }

    public void printCountWithTag(String tag) {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.printCountWithTag(tag);
        }
    }

    public void fillProduct(int offset, int count) {
        if (multithreadingTestHelper != null) {
            multithreadingTestHelper.fillProduct(offset, count);
        }
    }
}
